package com.mfangsoft.zhuangjialong.integration.newActivity.controller;

import java.text.ParseException;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mfangsoft.zhuangjialong.common.model.Page;
import com.mfangsoft.zhuangjialong.common.model.ResponseMessage;
import com.mfangsoft.zhuangjialong.common.utils.SysConstant;
import com.mfangsoft.zhuangjialong.integration.activity.model.BaseActivityInfo;
import com.mfangsoft.zhuangjialong.integration.newActivity.service.INewActivityService;

@Controller
@RequestMapping("/server")
public class NewActivityController {
	
	@Autowired
	INewActivityService newActivityServiceImpl;
	
	@RequestMapping(value="/addActivityTemplate",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<String> addActivityTemplate(@RequestBody Map<String,Object> map){
		ResponseMessage<String> message = new ResponseMessage<String>();
		try {
			newActivityServiceImpl.addActivityTemplate(map);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			return message;
		} catch (Exception e) {
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
			return message;
		}
		
	}
	@RequestMapping(value="/updateActivityTemplate",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<String> updateActivityTemplate(@RequestBody Map<String,Object> map){
		ResponseMessage<String> message = new ResponseMessage<String>();
		try {
			newActivityServiceImpl.updateActivityTemplate(map);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			return message;
		} catch (Exception e) {
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
			return message;
		}
		
	}
	@RequestMapping(value="/updateActivity1",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<String> updateActivity1(@RequestBody Map<String,Object> map){
		ResponseMessage<String> message = new ResponseMessage<String>();
		try {
			newActivityServiceImpl.updateActivity(map);
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			return message;
		} catch (Exception e) {
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
			return message;
		}
		
	}
	@RequestMapping(value="/selectActivityTemplate",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<Page<Map<String,Object>>> selectActivityTemplate(@RequestBody Page<Map<String,Object>> page){
		ResponseMessage<Page<Map<String,Object>>> message = new ResponseMessage<Page<Map<String,Object>>>();
		try {
			message.setResult(newActivityServiceImpl.selectActivityTemplate(page));
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			return message;
		} catch (Exception e) {
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
			return message;
		}
		
	}
	@RequestMapping(value="/selectWeiFaBuPage",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<Page<Map<String,Object>>> selectWeiFaBuPage(@RequestBody Page<Map<String,Object>> page){
		ResponseMessage<Page<Map<String,Object>>> message = new ResponseMessage<Page<Map<String,Object>>>();
		try {
			message.setResult(newActivityServiceImpl.selectWeiFaBuPage(page));
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			return message;
		} catch (Exception e) {
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
			return message;
		}
		
	}
	@RequestMapping(value="/selectPublishList",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<List<Map<String,Object>>> selectPublishList(@RequestBody Map<String,Object> map){
		ResponseMessage<List<Map<String,Object>>> message = new ResponseMessage<List<Map<String,Object>>>();
		try {
			message.setResult(newActivityServiceImpl.selectPublishList(Integer.valueOf(map.get("p_id").toString())));
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			return message;
		} catch (Exception e) {
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
			return message;
		}
		
	}
	@RequestMapping(value="/selectTemplateDetail",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<Map<String,Object>> selectTemplateDetail(@RequestBody Map<String,Object> map){
		ResponseMessage<Map<String,Object>> message = new ResponseMessage<Map<String,Object>>();
		try {
			message.setResult(newActivityServiceImpl.selectTemplateDetail(Integer.valueOf(map.get("p_id").toString())));
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			return message;
		} catch (Exception e) {
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
			return message;
		}
		
	}
	@RequestMapping(value="/selectActivityDetail",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<Map<String,Object>> selectActivityDetail(@RequestBody Map<String,Object> map){
		ResponseMessage<Map<String,Object>> message = new ResponseMessage<Map<String,Object>>();
		try {
			message.setResult(newActivityServiceImpl.selectActivityDetail(Integer.valueOf(map.get("activity_id").toString())));
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			return message;
		} catch (Exception e) {
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
			return message;
		}
		
	}
	@RequestMapping(value="/selectActivityStatistics",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	public ResponseMessage<Map<String,Object>> selectActivityStatistics(@RequestBody Map<String,Object> map){
		ResponseMessage<Map<String,Object>> message = new ResponseMessage<Map<String,Object>>();
		try {
			message.setResult(newActivityServiceImpl.selectActivityStatistics(Integer.valueOf(map.get("activity_id").toString())));
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			return message;
		} catch (Exception e) {
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
			return message;
		}
		
	}
	/**
	 * 活动列表
	 * @param page
	 * @return
	 * @throws ParseException
	 */
	@RequestMapping(value="/selectActivityPage",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin 
	public ResponseMessage<Page<Map<String,Object>>> selectActivityPage(@RequestBody Page<Map<String,Object>> page){
		ResponseMessage<Page<Map<String,Object>>> message = new ResponseMessage<Page<Map<String,Object>>>();
		try {
			Page<Map<String,Object>> list = newActivityServiceImpl.selectActivityPage(page);
			message.setResult(list);
			return message;
		} catch (Exception e) {
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
			return message;
		}
		
	}
	@RequestMapping(value="/selectActivityApplyListPage",method=RequestMethod.POST)
	@ResponseBody
	@CrossOrigin 
	public ResponseMessage<Page<Map<String,Object>>> selectActivityApplyListPage(@RequestBody Page<Map<String,Object>> page){
		ResponseMessage<Page<Map<String,Object>>> message = new ResponseMessage<Page<Map<String,Object>>>();
		try {
			Page<Map<String,Object>> list = newActivityServiceImpl.selectActivityApplyListPage(page);
			message.setResult(list);
			return message;
		} catch (Exception e) {
			e.printStackTrace();
			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
			return message;
		}
		
	}
	
	
}
